public class Solution {
    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }
        boolean negative = num < 0;
        num = Math.abs(num);
        StringBuffer digits = new StringBuffer();
        while (num > 0) {
            digits.append(num % 7);
            num /= 7;
        }
        if (negative) {
            digits.append('-');
        }
        return digits.reverse().toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] testNumbers = {100, -7, 0, 49, -50};
        for (int num : testNumbers) {
            String result = solution.convertToBase7(num);
            System.out.println("Decimal: " + num + " -> Base 7: " + result);
        }
    }
}
